package com.white.service.imp;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.white.bean.SearchHistory;
import com.white.mapper.SearchHistoryMapper;
import com.white.service.SearchHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SearchHistoryServiceImpl extends ServiceImpl<SearchHistoryMapper, SearchHistory> implements SearchHistoryService {
    @Autowired
    SearchHistoryMapper searchHistoryMapper;

    @Override
    public boolean create(SearchHistory searchHistory) {
        try {
            SearchHistory history = searchHistoryMapper.selectByContent(searchHistory.getContent());
            if (history == null) {
                searchHistoryMapper.create(searchHistory);
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public List<SearchHistory> searchByUserId(Long userId) {
        return searchHistoryMapper.searchByUserId(userId);
    }

    @Override
    public void deleteById(Long searchHistoryId) {
        searchHistoryMapper.deleteBySearchHistoryId(searchHistoryId);
    }
}
